<%--
  Created by IntelliJ IDEA.
  User: Mac
  Date: 2020/12/24
  Time: 10:41
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%String path = request.getContextPath()+"/";%>
<!DOCTYPE html>
<HTML>
<HEAD>
    <base href="<%=path%>">
    <TITLE>权限管理</TITLE>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link rel="stylesheet" href="ztree/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="ztree/js/jquery-1.4.4.min.js"></script>
    <script type="text/javascript" src="ztree/js/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="ztree/js/jquery.ztree.excheck.js"></script>
    <SCRIPT LANGUAGE="JavaScript">
        var zTreeObj;
        // zTree 的参数配置，深入使用请参考 API 文档（setting 配置详解）
        var setting = {
            check:{
                enable:true
            },
            data: {
                simpleData: {
                    enable: true
                }
            },
            callback:{
                onCheck:nodeCheck
            }

        };
        function clearCheckedOldNodes() {
            var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
                nodes = zTree.getChangeCheckedNodes();
            for (var i=0, l=nodes.length; i<l; i++) {
                nodes[i].checkedOld = nodes[i].checked;
            }
        }
        function nodeCheck(event,treeId,treeNode){

            var resource_id = treeNode.id;
            // 从作用域中去除角色id
            var role_id='${roleId}';
            var zTree = $.fn.zTree.getZTreeObj("treeDemo");
            var changeNodes = zTree.getChangeCheckedNodes();
            changeCount = zTree.getChangeCheckedNodes().length;
            // 获取当前节点的操作状态
            var status = treeNode.checked;
            // 当前发生改变的所有节点的id
            var param="status="+status+"&roleId="+role_id;
            for(var i=0;i<changeNodes.length;i++){
               // alert(changeNodes[i].id)
                param+="&ids="+changeNodes[i].id;
            }
            clearCheckedOldNodes();
            alert('resources/savePermission2?'+param)
            $.ajax({
                url:'resources/savePermission2?'+param,
                dataType:'json',
                type:'get',
                success:function (ret) {

                }
            });
            // $.ajax({
            //     url:'resources/savePermission',
            //     data:{
            //         roleId:role_id,
            //         resourceId:resource_id
            //     },
            //     type:'post',
            //     dataType:'json',
            //     success:function(ret){
            //         if(ret.status){
            //             // alert('操作成功');
            //         }else{
            //             alert('操作失败');
            //         }
            //     }
            //
            // });

        }
        // zTree 的数据属性，深入使用请参考 API 文档（zTreeNode 节点数据详解）
       console.log('${result}')
        var zNodes=JSON.parse('${result}');
        $(document).ready(function(){
                zTreeObj = $.fn.zTree.init($("#treeDemo"), setting, zNodes);

        });
    </SCRIPT>
</HEAD>
<BODY>
<div>
    <ul id="treeDemo" class="ztree"></ul>
</div>
</BODY>
</HTML>
